/*
 * 项目名称:    wms-server-jeecg
 * 创建人员:    FanZhiwen
 * 创建时间:    2023-10-16
 */
package org.jeecg.modules.flow.callback.inbound.other;

import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.business.third.entity.EmsOrDmsDeliveryDto;
import org.jeecg.modules.business.third.service.IEmsOrDmsDeliveryOperateService;
import org.jeecg.modules.flow.sys.common.BaseCustomBeanRun;
import org.jeecg.modules.flow.sys.entity.dto.BaseFlowDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 横剪退料(条料)主动调用MDS可退空料架请求
 *
 * @author FanZhiwen
 * @version 1.0.0
 * @since 2023-10-16
 */
@Component
@Slf4j
public class R14CanReturnBeforeBean<T> extends BaseCustomBeanRun<T> {
    @Autowired
    private IEmsOrDmsDeliveryOperateService emsOrDmsDeliveryOperateService;

    @Override
    public void actureRun() {
        //根据任务id创建入库单
        BaseFlowDto baseFlowDto = this.getBaseFlowDto();
        // 获取请求参数
        String taskId = baseFlowDto.getInfoId();
        EmsOrDmsDeliveryDto deliveryDto = new EmsOrDmsDeliveryDto();
        deliveryDto.setTaskId(taskId);
        deliveryDto.setType(2);
        log.info("调用MDS可退空料架开始");
        try {
            boolean warehouse = emsOrDmsDeliveryOperateService.warehouse(deliveryDto);
            if (!warehouse) {
                baseFlowDto.setCurrentFailed(true);
                baseFlowDto.setResult(Result.error("通知MDS可退料架请求失败"));
            } else {
                baseFlowDto.setResult(Result.OK().success("通知MDS可退料架请求成功"));
            }
        } catch (Exception e) {
            log.error("调用EMS可退空料架异常", e);
            baseFlowDto.setCurrentFailed(true);
            baseFlowDto.setResult(Result.error("通知MDS可退料架请求失败"));
        }
    }
}
